//
//  BootPageView.m
//  chatAI
//
//  Created by 陈镇 on 2023/4/24.
//

#import "BootPageView.h"
//#import "WangYiReqManager.h"
@interface BootPageView ()

/** <#注释#>*/
@property (nonatomic, strong) UIScrollView * scrollView;

@end

@implementation BootPageView

-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        
        
        
        
        [self addSubview:self.scrollView];
   
        
        BootSubPageView *view1 = [[BootSubPageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//        view1.title.text =@"多国语言翻译";
//        view1.desc.text =@"功能强大、精通多国语言";
        view1.topImage.image = [UIImage imageNamed:@"引导页-1"];
        view1.pageImage.image = [UIImage imageNamed:@"boot_page_icon_1"];
        [self.scrollView addSubview:view1];
        
        BootSubPageView *view2 = [[BootSubPageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//        view2.title.text =@"拍照翻译";
//        view2.desc.text =@"不用打字，直接拍照轻松翻译";
        view2.topImage.image = [UIImage imageNamed:@"引导页-2"];;
        view2.pageImage.image = [UIImage imageNamed:@"boot_page_icon_2"];
        [self.scrollView addSubview:view2];
        
        
        BootSubPageView *view3 = [[BootSubPageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH*2, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//        view3.title.text =@"AI智能助手";
//        view3.desc.text =@"会答疑、能解闷，全能小助理";
        view3.topImage.image = [UIImage imageNamed:@"引导页-3"];;
        view3.isLast = YES;
        [self.scrollView addSubview:view3];
        
        self.scrollView.contentSize = CGSizeMake(view3.right, SCREEN_HEIGHT);
        
        [view3.nextBtn addTarget:self action:@selector(clcikItem) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}


-(UIScrollView *)scrollView{
    if(!_scrollView){
        _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
        _scrollView.pagingEnabled = YES;
        _scrollView.bounces = NO;
        _scrollView.showsHorizontalScrollIndicator = NO;
    }
    return _scrollView;
}

-(void)clcikItem{

//    [SLBaseRequest getRequestWithPath:@"https://www.baidu.com" parameters:@{} callBack:nil];
    
    
    self.hidden = YES;
    [self removeFromSuperview];
    

}


+(void)showBootPage:(UIView *)supuerView{
//    NSString *bootShow = (NSString *)[[WangYiReqManager shareMangager].globalCache objectForKey:kBootShow];
//    
//    if(!bootShow){
//        
//        BootPageView *view = [[BootPageView alloc] initWithFrame:SLWindow.bounds];
//        [supuerView addSubview:view];
//        [[WangYiReqManager shareMangager].globalCache setObject:@"1" forKey:kBootShow];
//        
//    }
}



@end


@implementation BootSubPageView

-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        self.backgroundColor = UIColorWhite;
        
        
        _topImage = [[UIImageView alloc] init];
        [self addSubview:self.topImage];
 
        _nextBtn = [QMUIButton createButtonTitle:@"立即体验" titleColor:UIColorWhite font:SLFontMakeBold(18)];
        _nextBtn.layer.cornerRadius = 7;
        _nextBtn.layer.masksToBounds = YES;
        _nextBtn.layer.borderColor = UIColorHex(#F8AE43FF).CGColor;
        _nextBtn.backgroundColor = UIColorHex(#F8AE43FF);
        _nextBtn.layer.borderWidth = 1;
        [self addSubview:self.nextBtn];

        _title = [QMUILabel createTextColor:UIColorHex(#333333FF) font:SLFontMakeBold(28) textAlignment:NSTextAlignmentCenter];
        
        [self addSubview:self.title];
        
        _desc = [QMUILabel createTextColor:UIColorHex(#333333FF) font:SLFontMakeRegular(16) textAlignment:NSTextAlignmentCenter];
        [self addSubview:self.desc];
        
        _pageImage = [[UIImageView alloc] init];
        [self addSubview:self.pageImage];
        
        
    }
    return self;
}


-(void)layoutSubviews{
    [super layoutSubviews];
    
    if(_topImage.image){
        CGFloat height = _topImage.image.size.height/_topImage.image.size.width * self.width;
        _topImage.frame = CGRectMake(0, 0, self.width, height);
    }
    
    _nextBtn.frame = CGRectMake((SCREEN_WIDTH - MYDistance(188*2))/2,self.height -  bottomToViewNO(26) - 50, MYDistance(188*2), MYDistance(46*2));
    
    _desc.frame = CGRectMake(0, _nextBtn.top -35 -22, self.width, 22);
    
    _title.frame = CGRectMake(0, _desc.top - 10 - 40, self.width, 40);
    
    _pageImage.frame = CGRectMake((self.width - 33)/2, _nextBtn.center.y, 33, 4);
    if(!_isLast){
        self.nextBtn.hidden = YES;
        self.pageImage.hidden = NO;
    }else{
        self.nextBtn.hidden = NO;
        self.pageImage.hidden = YES;
    }
}

-(void)setIsLast:(BOOL)isLast{
    _isLast = isLast;
    if(!isLast){
        self.nextBtn.hidden = YES;
    }
}


@end
